package com.opages.mvc.adapter.nacos.discovery;

import com.netflix.loadbalancer.Server;
import com.opages.mvc.adapter.common.client.ServiceInstance;

import java.util.Map;

/**
 * @author daizhong.liu
 * @create 2020-07-09 17:19
 **/
public class NacosServiceInstance extends Server implements ServiceInstance {
    private String serviceId;

    private String host;

    private int port;

    private boolean secure;

    private Map<String, String> metadata;

    public NacosServiceInstance(String host, int port) {
        super(host, port);
        this.host = host;
        this.port = port;
    }

    @Override
    public String getServiceId() {
        return serviceId;
    }

    @Override
    public boolean isSecure() {
        return secure;
    }

    @Override
    public Map<String, String> getMetadata() {
        return metadata;
    }

    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    }

    @Override
    public void setHost(String host) {
        this.host = host;
    }

    @Override
    public void setPort(int port) {
        this.port = port;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public void setMetadata(Map<String, String> metadata) {
        this.metadata = metadata;
    }

    @Override
    public String getHost() {
        return host;
    }

    @Override
    public int getPort() {
        return port;
    }

    @Override
    public String getScheme() {
        if(secure) {
            return "https";
        }
        return "http";
    }
}
